(function (window, undefined) {
    let t = null
    $.fn.lazyLoad = function () {
        //保存this
        let _this = this
        //定义lazyload函数
        function lazyLoad() {
            //定时器
            if (t) clearTimeout
            t = setTimeout(() => {
                //获取可视窗口高度：窗口高度+滚动gaodu
                let windowH = Window.innerHeight || document.documentElement.clientHeight
                let scrollH = document.body.scrollTop || document.documentElement.scrollTop
                let showH = windowH + scrollH
                //获取所有的图片
                // let imgs = document.querySelectorAll('.lazy')
                // 把this赋值给imgs
                let imgs = _this
                // 遍历     判断 图片上边距距离浏览器上面和可视窗口高度的大小
                for (let i = 0; i < imgs.length; i++) {
                    if (imgs[i].offsetTop < showH) {
                        imgs[i].src = imgs[i].getAttribute('data-src')
                    }
                }


            }, 100)
        }

        lazyLoad()
        window.onscroll = lazyLoad
    }



})(window)